import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as express from 'express';
import { logger } from './middleware/logger.middleware';
import { TransformInterceptor } from './interceptor/transform.interceptor';
import { HttpExceptionFilter } from './filter/http-exception.filter';
import { AllExceptionFilter } from './filter/any-exception.filter';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';


async function bootstrap() {
	const app = await NestFactory.create(AppModule);

	app.use(express.json())	// for parsing application/json
	app.use(express.urlencoded({extended: true}))	// For parsing application/x-www-form-urlencoded
	app.use(logger)
	// 全局拦截器
	app.useGlobalInterceptors(new TransformInterceptor())
	app.setGlobalPrefix('api');
	app.useGlobalFilters(new HttpExceptionFilter())
	app.useGlobalFilters(new AllExceptionFilter())


	// 配置swagger
	const options = new DocumentBuilder()
		.setTitle('nest-demo')
		.setDescription('sc`s nest-demo API Document')
		.setVersion('1.0')
		.addTag('1.0')
		.build()
	const document = SwaggerModule.createDocument(app, options)
	SwaggerModule.setup('api-doc', app, document)
	
	await app.listen(3000);
}
bootstrap();
